package app.netant.book.xiaoshuotxt;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
import app.netant.book.base.BaseEntity;
import app.netant.book.base.BasePage;
import cn.lily.com.enviroment.Enviroment;

public class XiaoShuoTxtPage extends BasePage {

	public XiaoShuoTxtPage(String netSite) {
		super(netSite);
		this.tableKey = "xiaoshuotxt";
		this.selectKey = ".w990 table.ttop tbody tr";
		this.preHref = "http://www.xiaoshuotxt.org";
	}

	@Override
	public String buildHref(Element element) {	
		Elements children = element.children();
		if(children.size()>1){
			Elements childs = children.get(1).select("a");		
			if(childs.size()>0){
				String href = childs.get(0).attr("href");
				if(href.startsWith("/")){
					href = this.preHref + href;
				}
				return href;
			}

		}
		return null;		
	}

	@Override
	public BaseEntity buildEntity() {
		return new XiaoShuoTxtEntity();
	}

	@Override
	public BaseDetail buildDetail(String href) {
		return new XiaoShuoTxtDetail(href);
	}

	@Override
	public void afterEntity(BaseEntity entity, Element element) {
		
	}
	
	public static void main(String[] args) {
		Enviroment.createEnv();
		Enviroment.getEnv().getLogBean().beginLog();
		XiaoShuoTxtPage page = new XiaoShuoTxtPage("http://www.xiaoshuotxt.org/top/allbook.php");
		page.analyseHref();
	}
	
}
